
"""测试菜单选项"""

import wx


class MenuFrame(wx.Frame):
    """Menu Class"""
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Menu Frame")

        self.panel = p = wx.Panel(self, -1)

        menuBar = wx.MenuBar()
        fileMenu = wx.Menu()
        fileMenu.Append(-1, "打开", "一些帮助信息")
        fileMenu.Append(-1, "保存", "一些帮助信息")
        fileMenu.AppendSeparator()
        fileMenu.Append(wx.MenuItem(fileMenu, -1, "关闭文件", ""))
        exitItem = fileMenu.Append(-1, "退出")
        exitItem.Enable(False)  #让菜单不可用
        menuBar.Append(fileMenu, "文件")
        editMenu = wx.Menu()
        editMenu.Append(-1, "复制")
        editMenu.Append(-1, "粘贴")
        menuBar.Append(editMenu, "编辑")
        helpMenu = wx.Menu()
        helpMenu.Append(-1, "帮助")
        helpMenu.Append(-1, "关于我们")
        helpMenu.Append(-1, "更新")
        menuBar.Append(helpMenu, "帮助")
        self.Bind(wx.EVT_MENU, self.onExit, exitItem)
        self.SetMenuBar(menuBar)
        self.GetMenuBar()  # 从frame中获取一个菜单栏

        # 弹出式菜单
        self.popupmenu = wx.Menu()
        self.popupmenu.SetTitle("Title")
        for text in "one two three for five".split():
            item = self.popupmenu.Append(-1, text)
            self.Bind(wx.EVT_MENU, self.onPopupItem, item)
        p.Bind(wx.EVT_CONTEXT_MENU, self.onShowPopum)

    def onPopupItem(self, e):
        item = self.popupmenu.FindItemById(e.GetId())
        text = item.GetText()
        wx.MessageBox("You selected item '%s'" % text)

    def onShowPopum(self, e):
        pos = e.GetPosition()
        pos = self.panel.ScreenToClient(pos)
        self.panel.PopupMenu(self.popupmenu, pos)

    def onExit(self, e):
        self.Close()





if __name__ == "__main__":
    app = wx.App()
    frame = MenuFrame()
    frame.Show()
    app.MainLoop()